﻿Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Text
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls

Namespace DotNetNuke.Modules.ActiveForums.Controls
    <ParseChildren(True, ""), ToolboxData("<{0}:toggle runat=server></{0}:toggle>")> _
    Public Class Toggle
        Inherits WebControl
        Private _key As String
        Private _imagePath As String
        Private _cssClassOn As String
        Private _cssClassOff As String
        Private _toggleBehavior As Integer
        Private _isVisible As Boolean = True
        Public Property ToggleBehavior() As Integer
            Get
                Return _toggleBehavior
            End Get
            Set(ByVal value As Integer)
                _toggleBehavior = value
            End Set
        End Property
        Public Property Key() As String
            Get
                Return _key
            End Get
            Set(ByVal value As String)
                _key = value
            End Set
        End Property
        Public Property ImagePath() As String
            Get
                Return _imagePath
            End Get
            Set(ByVal value As String)
                _imagePath = value
            End Set
        End Property
        Public Property CssClassOn() As String
            Get
                Return _cssClassOn
            End Get
            Set(ByVal value As String)
                _cssClassOn = value
            End Set
        End Property
        Public Property CssClassOff() As String
            Get
                Return _cssClassOff
            End Get
            Set(ByVal value As String)
                _cssClassOff = value
            End Set
        End Property
        Public Property IsVisible() As Boolean
            Get
                Return _isVisible
            End Get
            Set(ByVal value As Boolean)
                _isVisible = value
            End Set
        End Property
        Protected Overrides Sub Render(ByVal writer As HtmlTextWriter)
            If IsVisible Then
                writer.Write("<div id=""imgGroup" & Key & """ class=""" & CssClassOn & """ onclick=""toggleGroup('" & Key & "','" & CssClassOn & "','" & CssClassOff & "');""></div>")
            Else
                writer.Write("<div id=""imgGroup" & Key & """ class=""" & CssClassOff & """ onclick=""toggleGroup('" & Key & "','" & CssClassOn & "','" & CssClassOff & "');""></div>")
            End If
        End Sub

        Private Sub Toggle_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
            EnableViewState = False
        End Sub
    End Class
    <ParseChildren(True, ""), ToolboxData("<{0}:toggledisplay runat=server></{0}:toggledisplay>")> _
    Public Class ToggleDisplay
        Inherits CompositeControl
        Private _content As ToggleContent
        Private _key As String
        Private _isVisible As Boolean = True
        Public Property IsVisible() As Boolean
            Get
                Return _isVisible
            End Get
            Set(ByVal value As Boolean)
                _isVisible = value
            End Set
        End Property
        Public Property Key() As String
            Get
                Return _key
            End Get
            Set(ByVal value As String)
                _key = value
            End Set
        End Property
        Public Overrides ReadOnly Property Controls() As System.Web.UI.ControlCollection
            Get
                EnsureChildControls()
                Return MyBase.Controls
            End Get
        End Property
        Protected Overrides Sub CreateChildControls()
            If Content IsNot Nothing Then
                Controls.Clear()
                Me.Controls.Add(Content)
            End If
        End Sub
        <Description("Initial content to render."), DefaultValue(Nothing, ""), Browsable(False), NotifyParentProperty(True), DesignerSerializationVisibility(DesignerSerializationVisibility.Content), PersistenceMode(PersistenceMode.InnerProperty)> _
       Public Property Content() As ToggleContent
            Get
                EnsureChildControls()
                Return _content
            End Get
            Set(ByVal Value As ToggleContent)
                _content = Value
            End Set
        End Property


        Protected Overrides Sub Render(ByVal writer As HtmlTextWriter)
            writer.Write("<div id=""group" & Key & """ class=""" & CssClass & """ style=""display:")
            If IsVisible Then
                writer.Write("block")
            Else
                writer.Write("none")
            End If
            writer.Write(";"">")
            Try
                Content.RenderControl(writer)
            Catch ex As Exception

            End Try

            writer.Write("</div>")

            '  writer.Write(Text)
        End Sub

        Private Sub ToggleDisplay_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
            If Context Is Nothing OrElse Page Is Nothing Then
                Return
            End If
            If Content IsNot Nothing Then
                Me.Controls.Add(Content)
            End If
            'EnableViewState = False
        End Sub
    End Class
    <ToolboxItem(False)> _
    Public Class ToggleContent
        Inherits Control

        Private Sub ToggleContent_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
            'EnableViewState = False
        End Sub
    End Class
End Namespace
